/**
 * @description 商品价格JS
 * @author 赵子靖
 * @since 2017-12-06
 */
var ShopPrice = function() {
    var t = {
        path :'',
        editor:'',
        init : function() {
            t.initView();
            t.initEvent();
        },
        initView : function() {
            
        },
        initEvent : function() {
            
        },
        //编辑节点
        updateShopPriceDialog:function(shopId){
            $("#dialog").load(t.path+"/busShopPrice/forwardUpdateShopPrice.do?shopId="+shopId,function(responseTxt,statusTxt,xhr){
                if(statusTxt=="success"){
                    $('#update-shop-price-dialog').modal();
                }else if(statusTxt=="error"){
                    alert("Error: "+xhr.status+": "+xhr.statusText);
                }
            }); 
        },
        //修改
        updateShopPrice:function(){
            var spId = $("#update-shop-price-dialog #spId").val();
            //商品价格
            var spUnit = $("#update-shop-price-dialog #spUnit").val();//商品单位
            var spSpecification = $("#update-shop-price-dialog #spSpecification").val();//商品规格
            var spMarketPrice = $("#update-shop-price-dialog #spMarketPrice").val();//商品市场单价
            var spCostPrice = $("#update-shop-price-dialog #spCostPrice").val();//商品成本单价
            var spPrice = $("#update-shop-price-dialog #spPrice").val();//商品单价
            var spUnitNum = $("#update-shop-price-dialog #spUnitNum").val();//数量转换
            var spLevelDiamondPrice = $("#update-shop-price-dialog #spLevelDiamondPrice").val();//钻石会员价格
            var spLevelGoldPrice = $("#update-shop-price-dialog #spLevelGoldPrice").val();//金牌会员价格
            var spLevelSilverPrice = $("#update-shop-price-dialog #spLevelSilverPrice").val();//银牌会员价格
            var spLevelCopperPrice = $("#update-shop-price-dialog #spLevelCopperPrice").val();//铜牌会员
            
            if(Util.isEmpty(spUnit)){
                $("#spUnitSpan").html("请输入商品单位。");
                $("#update-shop-price-dialog #spUnit").focus();
                return;
            }
            $("#spUnitSpan").html("");
            if(Util.isEmpty(spSpecification)){
                $("#spSpecificationSpan").html("请输入商品单位。");
                $("#update-shop-price-dialog #spSpecification").focus();
                return;
            }
            $("#spSpecificationSpan").html("");
            if(Util.isEmpty(spUnit)){
                $("#spUnitSpan").html("请输入商品规格。");
                $("#update-shop-price-dialog #spUnit").focus();
                return;
            }
            $("#spSpecificationSpan").html("");
            if(Util.isEmpty(spMarketPrice)){
                $("#spMarketPriceSpan").html("请输入商品。");
                $("#update-shop-price-dialog #spMarketPrice").focus();
                return;
            }
            $("#spMarketPriceSpan").html("");
            if(Util.isEmpty(spPrice)){
                $("#spPriceSpan").html("请输入商品市场价。");
                $("#update-shop-price-dialog #spPrice").focus();
                return;
            }
            $("#spPriceSpan").html("");
            if(Util.isEmpty(spUnitNum)){
                $("#spUnitNumSpan").html("请输入商品数量转换。");
                $("#update-shop-dialog #spUnitNum").focus();
                return;
            }
            $("#spUnitNumSpan").html("");
            if(Util.isEmpty(spLevelDiamondPrice)){
                $("#spLevelDiamondPriceSpan").html("请输入钻石会员价格。");
                $("#update-shop-dialog #spLevelDiamondPrice").focus();
                return;
            }
            $("#spLevelDiamondPriceSpan").html("");
            if(Util.isEmpty(spLevelGoldPrice)){
                $("#spLevelGoldPriceSpan").html("请输入金牌会员价格。");
                $("#update-shop-dialog #spLevelGoldPrice").focus();
                return;
            }
            $("#spLevelGoldPriceSpan").html("");
            if(Util.isEmpty(spLevelSilverPrice)){
                $("#spLevelSilverPriceSpan").html("请输入银牌会员价格。");
                $("#update-shop-dialog #spLevelSilverPrice").focus();
                return;
            }
            $("#spLevelSilverPriceSpan").html("");
            if(Util.isEmpty(spLevelCopperPrice)){
                $("#spLevelCopperPriceSpan").html("请输入铜牌会员价格。");
                $("#update-shop-dialog #spLevelCopperPricePrice").focus();
                return;
            }
            $("#spLevelCopperPriceSpan").html("");
            
            $.ajax({
                type:"POST",
                url:t.path+"/busShopPrice/updateShopPrice.do",
                dataType:"json",
                data:{
                    spId:spId,
                    spUnit:spUnit,
                    spSpecification:spSpecification,
                    spMarketPrice:spMarketPrice,
                    spCostPrice:spCostPrice,
                    spPrice:spPrice,
                    spUnitNum:spUnitNum,
                    spLevelDiamondPrice:spLevelDiamondPrice,
                    spLevelGoldPrice:spLevelGoldPrice,
                    spLevelSilverPrice:spLevelSilverPrice,
                    spLevelCopperPrice:spLevelCopperPrice
                },
                async: false,
                cache:false,
                success:function(data){
                    if(data.success){
                        alert("保存成功!");
                        $("#update-shop-price-dialog").modal('toggle');
                        $("#shop-table").bootstrapTable('refresh');
                    }else{
                        alert("保存失败!");
                    }
                }
            });
        }
    }
    return t;
}();